package com.service.Impl;

import com.bean.User;
import com.dao.LoginDao;
import com.service.LoginService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by huangjiaxiang on 2017/5/22.
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Resource
    private LoginDao loginDao;

    @Override
    public User getById(String name) {
        return loginDao.getByName(name);
    }

    @Override
    public int add(User user) {
        if (user.getName() == null) {
            return 0;
        }else{
            User users=getById(user.getUsername());
            if(users!=null){
                return 2;
            }
        }
        if (user.getAddress() == null) {
            return 0;
        }
        if (user.getCdkey() == null) {
            return 0;
        }
        if (user.getEmail() == null) {
            return 0;
        }
        if (user.getPassword() == null) {
            return 0;
        }
        if (user.getPhone() == null) {
            return 0;
        }
        if(user.getUsername()==null){
            return 0;
        }
        return loginDao.add(user);
    }

    @Override
    public User login(User user) {
        return loginDao.login(user);
    }
}
